package com.du.dupload;

import java.util.List;

public class TorrentDownloader implements IResourceDownloader {

	private static final String OUT = AppConfig.getInstance().getOutDir();
	private String torrentPath;
	private TorrentAria downloader;
	
	TorrentDownloader(String torrentPath) {
		super();
		this.torrentPath = torrentPath;
	}

	@Override
	public float getProgressPercent() {
		return downloader.getProgress();
	}

	@Override
	public void close() {

	}

	@Override
	public void startDownload() {
		
		downloader.download();

	}

	@Override
	public boolean isCompleted() {
		return downloader.isFinished();
	}

	@Override
	public boolean isError() {
		return downloader.isError();
	}

	@Override
	public void stopDownload() {
		downloader.cancel();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((downloader == null) ? 0 : downloader.hashCode());
		result = prime * result
				+ ((torrentPath == null) ? 0 : torrentPath.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		TorrentDownloader other = (TorrentDownloader) obj;
		if (torrentPath == null) {
			if (other.torrentPath != null)
				return false;
		} else if (!torrentPath.equals(other.torrentPath))
			return false;
		return true;
	}

	@Override
	public void initializeLoading() {
		downloader = new TorrentAria(torrentPath);
	}

	@Override
	public List<String> getPath() {
		
		return downloader.getResult();
	}

	

	@Override
	public String getName() {
		return downloader.getName();
	}

}
